package org.anachronos.jeep.ui.trace;
import org.anachronos.jeep.model.trace.Invocation;
import org.eclipse.core.commands.AbstractHandler;
import org.eclipse.core.commands.ExecutionEvent;
import org.eclipse.core.commands.ExecutionException;
import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.ui.handlers.HandlerUtil;

public class ShowBacktraceCommand extends AbstractHandler {

	@Override
	public Object execute(final ExecutionEvent event) throws ExecutionException {
		final IStructuredSelection currentSelection = 
			(IStructuredSelection) HandlerUtil.getCurrentSelection(event);
		final Invocation invocation = (Invocation) currentSelection.iterator().next();
		final TraceEditor editor = (TraceEditor) HandlerUtil.getActiveEditor(event);
		final BacktracePage backTracePage = editor.getBackTracePage();
		backTracePage.setInput(invocation);
		editor.setActivePage(backTracePage.getId());
		return null;
	}

}
